import config from "./config";
import metric from "./metric";
import log from "./logger";
import excelFulongCollector from "./excelfulongcollector";
import logfulongcollector from "./logfulongcollector";
import promailSpawn from "./promailspawn";
import zhangziTrainWorker from "./zhangzitrainworker";
import zhangziTrackWorker from "./zhangzitrackworker";
import kemenRadarWorker from "./kemanradarworker";
import wltlgTrainWorker from "./wltlgtrainworker";
import shiyaodiantrainworker from "./shiyaodiantrainworker";
import hongdonghaoqiangTrainWorker from "./hongdonghaoqiangtrainworker";
import mengdongmssqlcollector from "./mengdongmssqlcollector";
import xsyTrackWorker from "./xsytrackworker";
import xsyTrainWorker from "./xsytrainworker";
import mqttIot from "./mqttiot";

async function start() {
    // axios.defaults.timeout = 15 * 1000
    // 加载配置
    try {
        await config.init();
    } catch (e) {
        throw e;
    }
    // const os = require('os');
    // if (os.platform() === 'win32') {
    //     // 开守护进程
    //     promailSpawn.init();
    // }
    // 在线监控
    metric.init(60 * 1000);
    mqttIot.init()
    if (config.deviceName === "fulong") {
        logfulongcollector.init();
        excelFulongCollector.init();
    }
    if (config.deviceName === "zhangzi_train") {
        zhangziTrainWorker.init();
    }
    if (config.deviceName === "zhangzi_track") {
        zhangziTrackWorker.init();
    }
    if (config.deviceName.startsWith("kemen")) {
        kemenRadarWorker.init();
    }
    if (config.deviceName.startsWith("wltlg_train")) {
        wltlgTrainWorker.init();
    }
    if (config.deviceName.startsWith("shiyaodian_train")) {
        shiyaodiantrainworker.init();
    }
    if (config.deviceName.startsWith("hongdonghaoqiang_train")) {
        hongdonghaoqiangTrainWorker.init();
    }
    if (config.deviceName.startsWith("mengdong")) {
        mengdongmssqlcollector.init();
    }
    if (config.deviceName.startsWith("xsy_track")) {
        xsyTrackWorker.init();
    }
    if (config.deviceName.startsWith("xsy_train")) {
        xsyTrainWorker.init();
    }
    log.info("启动完成")
}

start();
// (function wait() {
//     console.log("防止退出");
//     setTimeout(wait, 1000 * 60);
// })()